<?php
   header("Content-Type: application/xml; charset=utf-8");
   echo "<?xml version=\"1.0\"?>\n";
   echo "<rss version=\"2.0\">";

   /********************************************************************************
    * File: rss.php
    * Desc: Returns RSS v0.92 feed for last 20 flickr photos.
    ********************************************************************************/
   require_once("inc/config.php");

   if ($config_flickrGroupId) { // show group's recent photos
      $photos = $f->groups_pools_getPhotos($config_flickrGroupId, 
         $config_flickrTags, $config_flickrUserId, 
         "original_format,date_taken,date_upload", $count, $page);         
   }
   else if ($config_flickrUserId) { // show user's recent photos
      $photoSearchParams = array(
         "user_id"=>$config_flickrUserId, 
         "tags"=>$config_flickrTags, 
         "extras"=>"original_format,date_taken,date_upload", 
         "per_page"=>$count, 
         "page"=>$page);
         
      $photos = $f->photos_search($photoSearchParams);   
   }
   
   $photos = $f->photos_search($photoSearchParams);
   
   if ($config_flickrGroupId) {
      $userInfo = $f->groups_getInfo($config_flickrGroupId);
   }
   else if ($config_flickrUserId) {
      $userInfo = $f->people_getInfo($config_flickrUserId);
   }
   $iconUrl  = "http://farm" . $userInfo['iconfarm'] . 
      ".static.flickr.com/" . $userInfo['iconserver'] . 
      "/buddyicons/" . $userInfo['nsid'] . ".jpg";
   
   $items = "";
   foreach ($photos['photo'] as $photo) {
      $photoInfo = $f->photos_getInfo($photo['id']);
      $date = getdate(strtotime($photoInfo['dates']['taken']));
      $items .=   
      "     <item>" . "\n" .
      "        <title>" . htmlspecialchars($photo['title'], ENT_QUOTES) . "</title>" . "\n" .
      "        <link>" . $config_siteUrl . "/index.php?id=" . $photo['id'] . "</link>" . "\n" .
      "        <guid>" . $config_siteUrl . "/index.php?id=" . $photo['id'] . "</guid>" . "\n" .
      "        <description>" . "\n" . 
      "           &lt;a href=&quot;" . $config_siteUrl . "/index.php?id=" . $photo['id'] . "&quot;&gt;" . "\n" .
      "              &lt;img style=&quot;border:0;&quot; src=&quot;" . $f->buildPhotoURL($photo) . "&quot;/&gt;" . "\n" .
      "           &lt;/a&gt;" . "\n" .
      "           &lt;p&gt;" . htmlspecialchars($photoInfo['description'], ENT_QUOTES) . "&lt;/p&gt;" . "\n" .
      "           &lt;p&gt;" . $date[month] . " " . $date[mday] . ", " . $date[year] . "&lt;/p&gt;" . "\n" .
      "        </description>" . "\n" .
      "     </item>\n";
   }
?>
<channel>
      <title><?php echo $config_siteTitle; ?></title>
      <link><?php echo $config_siteUrl; ?></link>
      <description><?php echo $config_siteDescription; ?></description>   
      <language>en-us</language>
      <image>
         <url><?php echo $iconUrl; ?></url>
         <title><?php echo $config_siteTitle; ?></title>
         <link><?php echo $config_siteUrl;?></link>
      </image>
      <?php echo $items; ?>
   </channel>
</rss>